package cn.genmer.test.security.utils;

import cn.genmer.test.security.common.AmapKeyEnum;
import cn.genmer.test.security.common.CommonResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/amap")
@Api(tags = "高德Web服务控制器")
public class AmapUtils {

    /**
     * 高德正向地理编码接口
     */
    private static final String AMAP_GEO_URL = "http://restapi.amap.com/v3/geocode/geo?";
    /**
     * 高德POI搜索接口
     */
    private static final String AMAP_POI_URL = "https://restapi.amap.com/v3/place/text?";
    /**
     * 高德POI搜索接口
     */
    private static final String AMAP_IP_URL = "https://restapi.amap.com/v5/ip?";

    /**
     * 地址查询
     * @param adress
     * @return
     */
    public static CommonResult geo(String adress){

        String param = "address=" + adress + "&key=" + AmapKeyEnum.WEBSERVER.getKey();
       return HttpSendClient.doGet(AMAP_GEO_URL + param);
    }

    /**
     * poi查询
     * @param adress
     * @return
     */
    public static CommonResult poi(String adress){

        String param = "keywords=" + adress + "&key=" + AmapKeyEnum.WEBSERVER.getKey();
        return HttpSendClient.doGet(AMAP_POI_URL + param);
    }

    /**
     * 根据ip查询地址
     * @param ip
     * @return
     */
    public static CommonResult ip(String ip){

        String param = "ip=" + ip + "&type=4&key=" + AmapKeyEnum.WEBSERVER.getKey();
        return HttpSendClient.doGet(AMAP_IP_URL + param);
    }


}
